<!-- 调拨单记录 -->
<template>
  <div id="change">
    <div class="change-top">
      单据日期&nbsp;
<<<<<<< HEAD
      <el-date-picker size="small" style="width: 150px;" v-model="listDate" type="date" placeholder="选择日期">
      </el-date-picker>
      &nbsp;&nbsp;部门&nbsp;
      <el-select v-model="test1" size="small" style="width: 150px;">
      </el-select>&nbsp;&nbsp;
      <span>
        <el-button size="small">保存</el-button>
=======
      <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" size="small" style="width: 150px;"
        v-model="costAdjustHeader.createDate" type="date" placeholder="选择日期">
      </el-date-picker>
      &nbsp;&nbsp;
      <span>
        <el-button size="small" @click="saveCostAdjust">保存</el-button>
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
        <el-button size="small" type="success">审核</el-button>
      </span>
      <PublicLink />
    </div>
    <div class=" change-content">
<<<<<<< HEAD
      <el-table @row-click="handlerClick" :row-style="{ height: '55px' }" show-summary :summary-method="getSummaries"
        height="450px" :data="tableData" border style="width: 100%;font-size: 13px;">
        <el-table-column prop="goodsId" label="商品编号" width="240">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit" v-model="scope.row.goodsId"></el-input>
            <span v-else>{{ scope.row.goodsId }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="unit" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="brand" label="品牌" width="150">
        </el-table-column>
        <el-table-column prop="remark" label="调整金额" width="150">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit" v-model="scope.row.remark"></el-input>
            <span v-else>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="unit" label="仓库" width="150">
          <template slot-scope="scope">
            <el-select size="small" v-if="scope.row.isEdit" v-model="scope.row.num"></el-select>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="150">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit" v-model="scope.row.remark"></el-input>
            <span v-else>{{ scope.row.remark }}</span>
=======
      <el-table @row-click="handlerClick" :row-style="{ height: '55px' }" height="450px"
        :data="costAdjustHeader.detailList" border style="width: 100%;font-size: 13px;">
        <el-table-column width="120">
          <el-button size="mini" @click="addRow"><i class="el-icon-circle-plus-outline"></i></el-button>
          <el-button size="mini" @click="reduceRow"><i class="el-icon-remove-outline"></i></el-button>
        </el-table-column>
        <el-table-column prop="goodcode" label="商品编号" width="240">
          <template slot-scope="scope">
            <el-input style="width: 160px;" size="small" v-model="scope.row.goodcode"></el-input>
            <el-button @click="goodsShow = true" size="small"><i class="el-icon-more"></i></el-button>
          </template>
        </el-table-column>
        <el-table-column prop="goodname" label="商品名称" width="120">
        </el-table-column>
        <el-table-column prop="unitname" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="cost" label="调整金额" width="150">
          <template slot-scope="scope">
            <el-input size="small" v-model="scope.row.cost"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="wid" label="仓库" width="150">
          <template slot-scope="scope">
            <el-select size="small" v-model="scope.row.wid">
              <el-option v-for="(wid, index) in storeList" :key="index" :label="wid.storeHomeName" :value="wid.shId">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="detailRemark" label="备注" width="150">
          <template slot-scope="scope">
            <el-input size="small" v-model="scope.row.detailRemark"></el-input>
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
          </template>
        </el-table-column>
      </el-table>
      <el-button style="position: relative;right: -1200px;" @click="goto('costChangeBill')">历史单据</el-button>
    </div>
  </div>
</template>

<script>
import PublicLink from '../public_com/PublicLink.vue';

export default {
  name: 'AddOutBound',
  components: {
    PublicLink,
  },
  data() {
<<<<<<< HEAD
    return {//分页参数
      listDate: '',
      switchValue: '1',
      providerId: '',
      test1: '',
      test2: '',
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value: '',
      input: '',
      tableData:
        [
          {
            goodsId: '',
            code: "",
            unit: '',
            pid: '',
            mid: '',
            aid: '',
            num: '',
            outWid: '',
            inputWid: '',
            aboutCode: '',
            remark: '',
            createDate: '',
            status: '',
            state: '',
            isEdit: false
          },
          {
            goodsId: '',
            code: "",
            unit: '',
            pid: '',
            mid: '',
            aid: '',
            num: '',
            outWid: '',
            inputWid: '',
            aboutCode: '',
            remark: '',
            createDate: '',
            status: '',
            state: '',
            isEdit: false
          },
          {}
        ],
      value1: '',
=======
    return {
      input: '',
      costAdjustHeader: {
        headerCode: '12121212',
        createDate: '',
        remark: '',
        detailList:
          [
            {
              goodcode: '',
              wid: '',
              unit: '',
              cost: '',
              detailRemark: '',
              unitname: ''
            },
          ],
      },
      storeList: []

>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
    }
  },
  methods: {
    goto(to) {
      this.$router.push(to)
    },
    handlerClick(row, column, event) {
      this.tableData.forEach((store, index) => {
        store.isEdit = false
      })
      row.isEdit = true
    },
<<<<<<< HEAD

    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (column.property === "num") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
        }
      });

      return sums;
    }

=======
    successMessage(msg) {
      this.$message({
        message: msg,
        type: 'success'
      });
    },
    errorMessage(msg) {
      this.$message({
        message: msg
        ,
        type: 'error'
      })
    },
    getStoreList() {
      this.axios.get('/info/storeHouse/getAllStore',
        {
          params: {
            cId: 1
          }
        }
      ).then(rs => {
        this.storeList = rs.data.storeList
      })
    },
    saveCostAdjust() {
      const priceRegix = /^[1-9]\d+(\.\d{2})?$/
      if (this.costAdjustHeader.createDate == '') {
        this.errorMessage("请选择单据日期")
        return
      }
      for (var i = 0; i < this.costAdjustHeader.detailList.length; i++) {
        if (this.costAdjustHeader.detailList[i].goodcode == '') {
          this.errorMessage("请填写第" + (i + 1) + "行商品编号");
          return;
        }
        if (this.costAdjustHeader.detailList[i].wid == '') {
          this.errorMessage("请选择第" + (i + 1) + "行的仓库");
          return;
        }
        if (!priceRegix.test(this.costAdjustHeader.detailList[i].cost)) {
          this.errorMessage("第" + (i + 1) + "行商品成本不合理");
          return;
        }
      }
      this.axios.post("/store/adjust/addCostAdjust",
        this.costAdjustHeader
      ).then(rs => {
        if (rs.data.code == 200) {
          this.successMessage("添加成功")
        }
        else {
          this.errorMessage("添加出错了")
        }
      })
    }

  },
  created() {
    this.getStoreList()
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
  }

}
</script>

<style scoped>
#change {
  width: 100%;
  height: 100%;
}

.change-top {
  width: calc(100% -20px);
  height: 60px;
  /* background-color: pink; */
  line-height: 60px;
  padding-left: 20px;
  font-size: 13px;
}

.change-content {
  width: 100%;
  height: calc(100% - 60px);
  margin-top: 40px;
  /* background-color: skyblue; */
}

.el-input,
.el-button {
  font-size: 13px;
}

/* 合计行整体样式修改开始 */
.el-table /deep/ .el-table__footer-wrapper tbody td {
  background-color: #fff1d4;
}

.el-table /deep/ .el-table__body tr:hover>td {
  background-color: #fff1d4;
}
</style>